package com.sunmi.usercenter.service;


import com.loopj.android.http.AsyncHttpClient;
import com.loopj.android.http.AsyncHttpResponseHandler;
import com.loopj.android.http.BinaryHttpResponseHandler;
import com.loopj.android.http.JsonHttpResponseHandler;
import com.loopj.android.http.RequestParams;
/**
 * 项目名称：Sunmi-User-Center
 * 类描述：
 * 创建人：Abtswiath丶lxy
 * 创建时间：2016/6/8 16:06
 * 修改人：longx
 * 修改时间：2016/6/8 16:06
 * 修改备注：
 */
public class HttpClient {
    private static AsyncHttpClient client = new AsyncHttpClient(); // 实例话对象
    static {
        client.setTimeout(11000); // 设置链接超时，如果不设置，默认为10s
    }

    /**
     * 用一个完整url获取一个string对象
     * @param urlString
     * @param res
     */
    public static void get(String urlString, AsyncHttpResponseHandler res) {
        client.get(urlString, res);
    }

    /**
     * url里面带参数
     * @param urlString
     * @param params
     * @param res
     */
    public static void get(String urlString, RequestParams params, AsyncHttpResponseHandler res) {
        client.get(urlString, params, res);
    }



    /**
     * 不带参数，获取json对象或者数组
     *
     * @param urlString
     * @param res
     */
    public static void get(String urlString, JsonHttpResponseHandler res) {
        client.get(urlString, res);
    }

    /**
     * 带参数，获取json对象或者数组
     * @param urlString
     * @param params
     * @param res
     */
    public static void get(String urlString, RequestParams params, JsonHttpResponseHandler res) {
        client.get(urlString, params, res);
    }

    /**
     * 下载数据使用，会返回byte数据
     * @param uString
     * @param bHandler
     */
    public static void get(String uString, BinaryHttpResponseHandler bHandler) {
        client.get(uString, bHandler);
    }

    /**
     * 携带params的参数和cookie
     * @param url
     * @param params
     * @param responseHandler
     * @param cook
     */
    public static void get(String url, RequestParams params, AsyncHttpResponseHandler responseHandler,String cook){
        client.addHeader("ifd__user_login", cook);
        client.get(url, params, responseHandler);
    }

    /**
     * url里面带参数和Cookie
     * @param url
     * @param responseHandler
     * @param cook
     */
    public static void get(String url, AsyncHttpResponseHandler responseHandler,String cook){
        client.addHeader("ifd__user_login", cook);
        client.get(url, responseHandler);
    }


    /**
     * url里面带参数
     * @param urlString
     * @param params
     * @param res
     */
    public static void post(String url, RequestParams params, AsyncHttpResponseHandler responseHandler) {
        client.post(url, params, responseHandler);
    }
    
    public static void post(String url,AsyncHttpResponseHandler responseHandler){
    	client.post(url, responseHandler);
    }

    public static void post(String url, RequestParams params, AsyncHttpResponseHandler responseHandler,String cook){
        client.addHeader("ifd__user_login", cook);
        client.post(url, params, responseHandler);
    }

    public static void post(String url, AsyncHttpResponseHandler responseHandler,String cook){
        client.addHeader("ifd__user_login", cook);
        client.post(url, responseHandler);
    }




    public static AsyncHttpClient getClient() {
        return client;
    }
}

